#include <linux/linkage.h>

#include <asm/assembler.h>
#include <asm/errno.h>

#define SYS_ERROR0	(0x9f0000)

#define TI_FLAGS	(4 * 0)
#define TI_PREEMPT  (4 * 1)
#define TI_CPU_DOMAIN (4 * 2)
#define TI_CPU_SAVE (4 * 3)

#define TIF_NEED_RESCHED	1
#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)

#define PT_REGS_SIZE	(4 * 18)
#define SVC_REGS_SIZE	(4 * 20)

#define S_FRAME_SIZE 	(4 * 18)
#define S_R0		(4 * 0)
#define S_SP		(4 * 13)
#define S_PC		(4 * 15)
#define S_PSR		(4 * 16)
#define S_OLD_R0	(4 * 17)

@ Bad Abort numbers
@ -----------------
@
#define BAD_PREFETCH	0
#define BAD_DATA	1
#define BAD_ADDREXCPTN	2
#define BAD_IRQ		3
#define BAD_UNDEFINSTR	4

@
@ Most of the stack format comes from struct pt_regs, but with
@ the addition of 8 bytes for storing syscall args 5 and 6.
@ This _must_ remain a multiple of 8 for EABI.
@
#define S_OFF		8

/* 
 * The SWI code relies on the fact that R0 is at the bottom of the stack
 * (due to slow/fast restore user regs).
 */
#if S_R0 != 0
#error "Please fix"
#endif

	.macro	zero_fp
#ifdef CONFIG_FRAME_POINTER
	mov	fp, #0
#endif
	.endm

	.macro	alignment_trap, rtemp
#ifdef CONFIG_ALIGNMENT_TRAP
	ldr	\rtemp, .LCcralign
	ldr	\rtemp, [\rtemp]
	mcr	p15, 0, \rtemp, c1, c0
#endif
	.endm

	.macro	svc_exit, rpsr
	msr	spsr_cxsf, \rpsr
	ldmia	sp, {r0 - pc}^			@ load r0 - pc, cpsr
	.endm

	.macro	restore_user_regs, fast = 0, offset = 0
	ldr	r1, [sp, #\offset + S_PSR]	@ get calling cpsr
	ldr	lr, [sp, #\offset + S_PC]!	@ get pc
	msr	spsr_cxsf, r1			@ save in spsr_svc
	.if	\fast
	ldmdb	sp, {r1 - lr}^			@ get calling r1 - lr
	.else
	ldmdb	sp, {r0 - lr}^			@ get calling r0 - lr
	.endif
	add	sp, sp, #S_FRAME_SIZE - S_PC
	movs	pc, lr				@ return & move spsr_svc into cpsr
	.endm

	.macro	get_thread_info, rd
	mov	\rd, sp, lsr #13
	mov	\rd, \rd, lsl #13
	.endm

/*
 * These are the registers used in the syscall handler, and allow us to
 * have in theory up to 7 arguments to a function - r0 to r6.
 *
 * r7 is reserved for the system call number for thumb mode.
 *
 * Note that tbl == why is intentional.
 *
 * We must set at least "tsk" and "why" when calling ret_with_reschedule.
 */
scno	.req	r7		@ syscall number
tbl	.req	r8		@ syscall table pointer
why	.req	r8		@ Linux syscall (!= 0)
tsk	.req	r9		@ current thread_info
